﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace MyXMLPrase
{
    public partial class ValidateXMLInfomationDisplay : Form
    {
        public ValidateXMLInfomationDisplay()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.InitialDirectory = ".";
            //设置保存的固定格式 
            sfd.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            //保存文件名默认为日期+验证信息四个字.
            sfd.FileName = "验证信息_" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", ""); ;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (sfd.FileName == "")
                {
                    MessageBox.Show("文件名不能为空");
                    return;
                }
                String s = richTextBox1.Text;
                //换行 
                s.Replace("\n", "\r\n");
                try
                {
                    StreamWriter sw = new StreamWriter(sfd.FileName, false, Encoding.Unicode);
                    sw.WriteLine("验证XML输出信息\n");
                    sw.WriteLine(s);
                    sw.Dispose();   //释放资源
                    sw.Close();     //关闭数据源;

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }
        }
    }
}
